#include "virtualkeyboard.h"

VirtualKeyboard::VirtualKeyboard(QWidget *parent) : QWidget(parent) {
    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->setSpacing(5);  // 按钮间距优化[6](@ref)
    mainLayout->setContentsMargins(2, 2, 2, 2);  // 布局边距[7](@ref)
    mainLayout->setAlignment(Qt::AlignVCenter);

    // 生成A-Z字母按钮
    for (char c = 'A'; c <= 'Z'; ++c) {
        QPushButton *btn = createKeyButton(QString(c));
        mainLayout->addWidget(btn);
        letterButtons.append(btn);  // 存储按钮指针用于大小写切换[5](@ref)
    }

}

QPushButton* VirtualKeyboard::createKeyButton(const QString &text) {
    QPushButton *btn = new QPushButton(text);
    // 统一按钮样式[1](@ref)
    btn->setFixedSize(34, 34);
    btn->setStyleSheet(
        "QPushButton {"
        "  background: #F0F0F0;"
        "  border: 2px solid #CCCCCC;"
        "  border-radius: 5px;"
        "  font: bold 16px;"
        "}"
        "QPushButton:hover { background: #E0E0E0; }"
        "QPushButton:pressed { background: #D0D0D0; }"
        );
    // 连接点击信号
    connect(btn, &QPushButton::clicked, this, [=]() {
        emit keyPressed(btn->text());
    });
    return btn;
}
